package com.woniuxy.project.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.commons.request.ResPage;
import com.woniuxy.commons.service.FeignUserService;
import com.woniuxy.project.entity.UserDetails;
import com.woniuxy.project.mapper.UserDetailsMapper;
import com.woniuxy.project.service.UserDetailsService;
import com.woniuxy.project.vo.UserDetailsVo;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Slf4j
@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    @Resource
    private UserDetailsMapper userDetailsMapper;
    @Resource
    private FeignUserService feignUserService;
    @Override
    public ResPage<UserDetails> getUserDetailsList(UserDetailsVo userDetailsVo) {
        PageHelper.startPage(userDetailsVo.getPage(), userDetailsVo.getSize());
        List<UserDetails> list = userDetailsMapper.getUserDetailsList(userDetailsVo);
        PageInfo<UserDetails> pageInfo = new PageInfo<>(list);
        return new ResPage<>(pageInfo);
    }

    @GlobalTransactional
    @Override
    public Boolean disableAccount(Integer id) {
        feignUserService.disableAccount(id);
        return userDetailsMapper.disableAccount(id) == 1;
    }

    @GlobalTransactional
    @Override
    public Boolean enableAccount(Integer id) {
        feignUserService.enableAccount(id);
        return userDetailsMapper.enableAccount(id);
    }
}
